<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Master_controller extends CI_Controller {
	protected $view_data;
	protected $_language = "en";
	protected $_page_uri = "home";
	
	function __construct() {
		parent::__construct();
		$this->load->helper('htmlpurifier');
		$this->view_data['active_home'] = "";
		$this->view_data['active_about_us'] = "";
		$this->view_data['active_product'] = "";
		$this->view_data['active_news'] = "";
		$this->view_data['active_jobs'] = "";
		$this->view_data['active_contact'] = "";
		
		$this->load->library('session');
		$this->lang->load('fo', $this->session->userdata('language'));
		$_language = $this->session->userdata('language') == "english" ? "en" : "vi";
		
		$this->load->model('DNN_model');
		$this->load->model('Category_model');
		$this->load->model('Config_model');
		$this->load->model('Image_model');
		$this->load->model('Visitor_model');
		$this->view_data['categories'] = $this->Category_model->get_list_parent()->result();
		$this->view_data['yahoo1'] = $this->Config_model->get_by_key(YAHOO1)->row()->value;
		$this->view_data['yahoo2'] = $this->Config_model->get_by_key(YAHOO2)->row()->value;
		$this->view_data['skype1'] = $this->Config_model->get_by_key(SKYPE1)->row()->value;
		$this->view_data['skype2'] = $this->Config_model->get_by_key(SKYPE2)->row()->value;
		$this->view_data['email1'] = $this->Config_model->get_by_key(EMAIL1)->row()->value;
		$this->view_data['email2'] = $this->Config_model->get_by_key(EMAIL2)->row()->value;
		$this->view_data['search_text'] = $this->lang->line('input-key');
		$this->view_data['category'] = 0;
		$this->view_data['client_images'] = $this->Image_model->get_by_type(1)->result();
		$this->view_data['partner_images'] = $this->Image_model->get_by_type(2)->result();
		$this->view_data['ads_images'] = $this->Image_model->get_by_type(3)->result();
		//save visitor
		$data_arr = array (
			'ip' => $this->input->ip_address(),
			'created_date' => date('Y-m-d H:i:s'),
		);
		$this->Visitor_model->add($data_arr);
		$this->view_data['total_view'] = $this->Visitor_model->count_all();
		$this->view_data['today'] = $this->Visitor_model->today();
		$this->view_data['last_week'] = $this->Visitor_model->last_week();
		$this->view_data['last_month'] = $this->Visitor_model->last_month();
	}
	function render_page($data) {
		$this->load->view('master_view', $data);
	}
	function en($page) {
		$this->session->set_userdata('language', 'english');
		redirect(site_url().$page, 'refesh');
	}
	function vi($page) {
		$this->session->set_userdata('language', 'vietnamese');
		redirect(site_url().$page, 'refesh');
	}
	function _render_paging($count_all, $offset = 0, $per_page = DEFAULT_ITEM_PER_PAGE, $action = 'index', $uri_segment = 3) {
		$this->load->library('pagination');
		//Paging Config
 		$page_config['per_page'] = $per_page;
		$page_config['base_url'] = $this->_page_uri.'/'.$action.'/';
 		$page_config['total_rows'] = $count_all;
		$page_config['cur_page'] = $offset;
		$page_config['uri_segment'] = $uri_segment;
		$page_config['first_link'] =$this->lang->line('first');
		$page_config['last_link'] =$this->lang->line('last');
		$this->pagination->initialize($page_config);
		return $this->pagination->create_links();
	}
}